package com.lsmgc.cms.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期工具包
 */
public class DateUtils {
    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");

    /**
     * 计算两个日期的间隔小时
     * @param date1
     * @param date2
     * @return
     */
    public static int intervalHour(Date date1, Date date2){
        long from = date1.getTime();
        long to = date2.getTime();
        int hours = (int) ((to - from)/(1000 * 60 * 60));
        System.out.println("相差 " + hours + " 小时");
        return Math.abs(hours);
    }

    /**
     * 计算两个日期的间隔天数
     * @param date1
     * @param date2
     * @return
     */
    public static int intervalDay(Date date1, Date date2){
        long from = date1.getTime();
        long to = date2.getTime();
        int days = (int) ((to - from)/(1000 * 60 * 60 * 24));
        System.out.println("相差 " + days + " 天");
        return Math.abs(days);
    }

    /**
     * 计算两个日期的间隔分钟
     * @param date1
     * @param date2
     * @return
     */
    public static int intervalMinute(Date date1, Date date2){
        long from = date1.getTime();
        long to = date2.getTime();
        int minutes = (int) ((to - from)/(1000 * 60));
        System.out.println("相差 " + minutes + " 分钟");
        return Math.abs(minutes);
    }
}
